# -*- coding: utf-8 -*- 

import wx
import urllib2
import json
  
#import the newly created GUI file 
import main  
class CalcFrame(main.MyFrame1): 
   def __init__(self,parent): 
      main.MyFrame1.__init__(self,parent)  
		
   def Do(self,event): 
      #num = int(self.m_textCtrl1.GetValue()) 
      #choice1 = self.m_choice1.GetCurrentSelection()
      #choice2 = self.m_choice2.GetCurrentSelection()
      text1 = (self.m_textCtrl1.GetValue())
      text2 = (self.m_textCtrl2.GetValue())
      keyword = urllib2.quote(text1.encode("utf-8"))
      url = r'http://aidemo.youdao.com/trans?q='+keyword
      #keyword = 'my%20name%20is%20lily'
      #url = r'http://www.example.com/'
      try:
        html = urllib2.urlopen(url).read()
        html = json.loads(html);
        query = html['translation'][0]
        query = query.encode("gbk")
        result = query
      except:
        self.m_textCtrl2.SetValue(str("Wrong")) 
      else:
        self.m_textCtrl2.SetValue(str(result)) 
        
app = wx.App(False) 
frame = CalcFrame(None) 
frame.Show(True) 
#start the applications 
app.MainLoop()  